package com.src.myapplication.ui.view.fragmentpemgyou;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.facebook.drawee.view.SimpleDraweeView;
import com.google.gson.Gson;
import com.src.myapplication.R;
import com.src.myapplication.base.BaseFragmentSwp;
import com.src.myapplication.bean.PaiHangBangben;
import com.src.myapplication.config.UrlConfig;
import com.src.myapplication.widget.CommonAdapter;
import com.src.myapplication.widget.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/10/17.
 */
public class FrgmentPaiHang extends BaseFragmentSwp {

    private RecyclerView mRcv;

    @Override
    protected void initData(View view) {
        mRcv = (RecyclerView) view.findViewById(R.id.rcv);
    }


    @Override
    public int getLayoutId() {
        return R.layout.frgment_paihang;
    }

    @Override
    public int getid() {
        return R.id.swe;
    }

    @Override
    public String geturl() {
        return UrlConfig.PengYou.PENGYOU_PAIHANGBANG;
    }

    @Override
    public Class<? extends Object> getben() {
        return PaiHangBangben.class;
    }


    @Override
    public void addList(String string) {
        if (string != null) {
            Gson gson = new Gson();
            List<PaiHangBangben> list =new ArrayList<>();
            PaiHangBangben paiHangBangben = gson.fromJson(string, PaiHangBangben.class);
            list.add(paiHangBangben);
            CommonAdapter<PaiHangBangben> adapter = new CommonAdapter<PaiHangBangben>(getContext(), R.layout.xiaoxi_paihang_list, list) {
                @Override
                protected void convert(ViewHolder holder, PaiHangBangben paiHangBangben, int position) {
                    List<PaiHangBangben.CreditsBean> credits = paiHangBangben.getCredits();
//                    String nickname = credits.get(0).getNickname();
//                    String nickname = credits.get(1).getNickname();
//                    String nickname = credits.get(2).getNickname();
                    String avatar1 = credits.get(0).getAvatar();
                    String avatar2 = credits.get(1).getAvatar();
                    String avatar3 = credits.get(2).getAvatar();
                    SimpleDraweeView view1 = holder.getView(R.id.iv1);
                    SimpleDraweeView view2 = holder.getView(R.id.iv2);
                    SimpleDraweeView view3 = holder.getView(R.id.iv3);
                    view1.setImageURI(avatar1);
                    view2.setImageURI(avatar2);
                    view3.setImageURI(avatar3);
                }
            };
            LinearLayoutManager manager=new LinearLayoutManager(getContext());
            manager.setOrientation(LinearLayoutManager.VERTICAL);
            mRcv.setLayoutManager(manager);
            mRcv.setAdapter(adapter);
        }

    }

    @Override
    public void showLoadFailMsg() {

    }

}